package com.code.platform.book.controller;

import com.code.platform.book.BaseController;
import com.code.platform.common.exception.BusinessException;
import com.code.platform.common.open.OpenResponse;
import com.code.platform.common.utils.StringUtils;
import com.code.platform.modules.bookauthor.model.BookAuthor;
import com.code.platform.modules.bookauthor.service.IBookAuthor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by liuyj on 2017/1/1.
 */
@Controller
@RequestMapping(value = "/book/author")
public class AuthorController extends BaseController {


    @Autowired
    private IBookAuthor iBookAuthor;


    /**
     * 根据主键获取作者信息 liuyj
     *
     * @param id
     * @return
     */
    @RequestMapping(value = "getAuthorById")
    @ResponseBody
    public OpenResponse getAuthorById(String id) {
        OpenResponse openResponse = new OpenResponse();
        logger.info("根据主键获取作者信息。。");
        if (StringUtils.isBlank(id)) {
            logger.error("根据主键获取作者信息，参数为空，id【{}】", id);
            openResponse.setIsSuccess("false");
            openResponse.setErrorMessage("参数为空");
            return openResponse;
        }
        try {
            //获取作者信息
            BookAuthor bookAuthor = iBookAuthor.getAuthorById(id);
            logger.info("根据主键获取作者信息，成功");
            openResponse.setIsSuccess("true");
            openResponse.setResponse(bookAuthor);
        } catch (BusinessException e) {
            logger.error("根据主键获取作者信息，异常");
            e.printStackTrace();
            openResponse.setIsSuccess("false");
            openResponse.setErrorMessage("异常");
        }
        return openResponse;
    }


}
